﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BizModels;
using Repositories;
using WebLib;

namespace HinokyWeb.Controllers
{
    public class Web2048Controller : Controller
    {
        //
        // GET: /Web2048/

        public ActionResult Default()
        {
            return View();
        }

        [HttpPost]
        public ActionResult SaveScore(string name, int score)
        {
            var repo = new Web2048Repository();

            var result = repo.InsertScore(new Web2048ScoreT
            {
                Name = name,
                Score = score,
                IPAddress = WebHelper.GetClientUserIP()
            });

            return Json(new {Success = result, ErrorType = ""});
        }

        [HttpGet]
        public ActionResult GetTotalResult()
        {
            var repo = new Web2048Repository();

            var dataList = repo.GetScoreList();

            return Json(new {ScoreList = dataList}, JsonRequestBehavior.AllowGet);
        }
    }
}
